//查询供应商报价详情信息
function searchSupplierPrice($id){
	var object = $("#bag").html("");
	//获取提交路径
	
	object.load("test1",function(response,status,xhr){
		
		var data="supplierInfoNo=0";
		showAllSuplierProduct(data);
		//查询供应商基本商品信息
		var url="/trade-wzj-web/Supplier_quotaController_Yang/checkAllSupplierInfo";
		var datas="supplierInfoId=";
		var result=postMethod(url,"POST",datas);
		getSup(result);
	})
}



//获取当前供应商信息
function getSup($obj){
	
	var objDrop=$("#supplierSuppierDrop");
	objDrop.html("");
	var strDrop="<option value=0>--请选择--</option>";
	for(var i=0;i<$obj.length;i++){
		strDrop=strDrop+"<option value='"+$obj[i].supplierInfoID+"'>" +
							$obj[i].supplierName+
						"</option>";
	}
	objDrop.append(strDrop);
}

//下拉框改变显示方法
function changes(){
	var obj = $("#supb").html("");
	
	var url="/trade-wzj-web/Supplier_quotaController_Yang/checkAllSupplierIns";
	var datas="supplierInfoId="+$("#supplierSuppierDrop").val();
	var result=postMethod(url,"POST",datas);
	var priceNo=$("#priceNo").html("");
	var priceDate=$("#priceDate").html("");
	console.info(result);
	if(result.length>0){
	priceDate.append(result[0].supplierQuota.quotaDate);
	priceNo.append(result[0].supplierQuota.supplierquotaID)
	var str = "<p>"+result[0].supplierName+"</p>"+
				+"<p>"+result[0].supplierContacts+"</p>"+
				+"<p>"+result[0].supplierPhone+"</p>"+
				+"<p>"+result[0].supplierAddress+"</p>"+
				+"<p>"+result[0].supplierFax+"</p>";
	obj.append(str);
	}
	var data="supplierInfoNo="+$("#supplierSuppierDrop").val();
	showAllSuplierProduct(data);
	//$("#supplierSuppierDrop").selectedIndex = -1;
}





//显示供应商报价新增页面
function showAllSuplierProduct($data){
	
	var obj=$("#addSupplierProductTable tbody").html("");
	var url="/trade-wzj-web/Supplier_quotaController_Yang/getAllSupplierProduct";
	var result=postMethod(url,"POST",$data);
	var supplierPrice=result;
	var str="";
	if(supplierPrice.length>0){
		
	
	//报价总额
	var total=$("#priceTotal").html("");
	var d=0.0;
	
	var k=1;
		for(var i=0;i<supplierPrice.length;i++){
			d=d+(supplierPrice[i].productNum)*(supplierPrice[i].productPrice);
			str=str+
					"<tr>" +
						"<td>"+k+"</td>" +
						"<td>"+supplierPrice[i].productName+"</td>" +
						"<td>"+supplierPrice[i].productNum+"</td>" +
						"<td>"+supplierPrice[i].unit+"</td>" +
						"<td>"+supplierPrice[i].supplierQuota.quotaDate+"</td>" +
						"<td>"+supplierPrice[i].expirationDate+"</td>" +
						"<td>"+supplierPrice[i].productDelivery+"</td>" +
						"<td>"+supplierPrice[i].productPrice+"</td>" +
						"<td>"+supplierPrice[i].rental+"</td>" +
						"<td><span class='glyphicon glyphicon-stop'></span></td>" +
						
					"</tr>";
			k++;
			
		}
	
		total.append(d);
		str=str+"<tr>" +
		
			"<td><span class='glyphicon glyphicon-map-marker'></span></td>"+
			"<td><input type='text' name='productName' class='form-control' placeholder='品名' style='width:4rem;'></td>"+
			"<td><input type='text' name='productNum' class='form-control' placeholder='数量' style='width:4rem;'></td>"+
			"<td><input type='text' name='Unit' class='form-control' placeholder='单位' style='width:4rem;'></td>"+
			"<td><input type='text' name='quotaDate' class='form-control' placeholder='报价日期' style='width:4rem;'></td>"+
			"<td><input type='text' name='expirationDate' class='form-control' placeholder='报价截止日期' style='width:4rem;'></td>"+
			"<td><input type='text' name='productDelivery' class='form-control' placeholder='货期' style='width:4rem;'></td>"+
			"<td><input type='text' name='productPrice' class='form-control' placeholder='金额' style='width:4rem;'></td>"+
			"<td><input type='text' name='rental' class='form-control' placeholder='金额' style='width:4rem;'></td>"+
			"<td><a href='#' onclick='addSupplierProducts();'><span class='glyphicon glyphicon-plus'></span></a></td>"+
	"</tr>";
obj.append(str);
	}else{
		
	
				str=str+"<tr>" +
					
      				"<td><span class='glyphicon glyphicon-map-marker'></span></td>"+
      				"<td><input type='text' name='productName' class='form-control' placeholder='品名' style='width:4rem;'></td>"+
      				"<td><input type='text' name='productNum' class='form-control' placeholder='数量' style='width:4rem;'></td>"+
      				"<td><input type='text' name='Unit' class='form-control' placeholder='单位' style='width:4rem;'></td>"+
      				"<td><input type='text' name='quotaDate' class='form-control' placeholder='报价日期' style='width:4rem;'></td>"+
      				"<td><input type='text' name='expirationDate' class='form-control' placeholder='报价截止日期' style='width:4rem;'></td>"+
      				"<td><input type='text' name='productDelivery' class='form-control' placeholder='货期' style='width:4rem;'></td>"+
      				"<td><input type='text' name='productPrice' class='form-control' placeholder='金额' style='width:4rem;'></td>"+
      				"<td><input type='text' name='rental' class='form-control' placeholder='金额' style='width:4rem;'></td>"+
      				"<td><a href='#' onclick='addSupplierProducts();'><span class='glyphicon glyphicon-plus'></span></a></td>"+
				"</tr>";
	obj.append(str);
	}
}


//页面多行添加商品后，一次性提交数据库
function addSupplierProducts(){
	
	var addClientForm = $("#addSupplierProductForms").Validform({
		tiptype:1
	});
	
	var bool = addClientForm.check();
	if(bool==false){
		alert("请补充完整信息");
		return;
	}
	//提交数据信息
	var data ="supplierSuppiers="+$("#supplierSuppierDrop").val()+"&"+ $("#addSupplierProductForms").serialize();
	//提交路径
	var url="/trade-wzj-web/Supplier_quotaController_Yang/addSupplierPrice";
	var bol=postMethod(url,"POST",data);
	if(bol){
		alert("操作成功!");
	}else{
		alert("操作失败!");
	}
	var datas="supplierInfoNo="+$("#supplierSuppierDrop").val();
	showAllSuplierProduct(datas);
}





//新增供应商报价详情信息
function addSupPrice(){ 
	//获取新增信息
	var data="products="+products;
	//获取提交路径
	var url="";
	$.ajax({
		"type":"POST",
		"url":url,
		"data":data,
		"aysnc":false,
		"success":function(response){
			var list=response;
			showAllSuplierProduct(list);
			products=[];
		}
		
	})
}

//生成客户报价单
function changeClientPrice(){
	//获取选择的信息id,通过数据库查询后，再次添加到客户报价信息表中
	var ck=document.getElementByClassName("checkSupplier");
	//获取提交路径
	var url="";
	$.ajax({
		"type":"POST",
		"url":url,
		"data":ck,
		"async":false,
		"success":function(response){
			//如果返回真值,则提示成功,并停留当前信息
			if(response){
				alert("已生成客户报价信息");
			}
		}
	})
}

